<?php 
/* 
* Smarty plugin 
* ------------------------------------------------------------ 
* Type:     modifier 
* Name:     simplebbcode 
* Purpose:  Converts BBCode style tags to HTML tags. All potentially dangerous 
*           and typically unused codes removed. Useful for public texts like 
*           guestbooks. 
* Version:  1.4.4 
* Date:     11.06.2006 
* 
* Install:  Drop into the plugin directory 
* Author:   Sam 
* Homepage: http://rmc.net.ru 
* ------------------------------------------------------------ 
*/ 
function smarty_modifier_simplebbcode($message) { 
  $preg = array( 
            // 
//            '~<([^<]+)>~' => '&lt;$1&gt;',
            // 
          '~(?<!\\\\)\[s(?::\w+)?\](.*?)\[/s(?::\w+)?\]~si'                  => '<span style="text-decoration:line-through;">\1</span>',
          '/(?<!\\\\)\[color(?::\w+)?=(.*?)\](.*?)\[\/color(?::\w+)?\]/si'   => "<span style=\"color:\\1\">\\2</span>",
          '/(?<!\\\\)\[b(?::\w+)?\](.*?)\[\/b(?::\w+)?\]/si'                 => "<span style=\"font-weight:bold\">\\1</span>",
          '/(?<!\\\\)\[sup(?::\w+)?\](.*?)\[\/sup(?::\w+)?\]/si'                 => "<sup>\\1</sup>",
          '/(?<!\\\\)\[i(?::\w+)?\](.*?)\[\/i(?::\w+)?\]/si'                 => "<span style=\"font-style:italic\">\\1</span>",
          '/(?<!\\\\)\[u(?::\w+)?\](.*?)\[\/u(?::\w+)?\]/si'                 => "<span style=\"text-decoration:underline\">\\1</span>",

          // [email] 
          '/(?<!\\\\)\[email(?::\w+)?\](.*?)\[\/email(?::\w+)?\]/sei'         => "'<a href=\"mailto:'.str_replace('@', '@','$1').'\">'.str_replace('@', '@','$1').'</a>'",
          '/(?<!\\\\)\[email(?::\w+)?=(.*?)\](.*?)\[\/email(?::\w+)?\]/sei'   => "'<a href=\"mailto:'.str_replace('@', '@','$1').'\">$2</a>'",
          // [url] 
          '/(?<!\\\\)\[url(?::\w+)?\]www\.(.*?)\[\/url(?::\w+)?\]/si'        => "<a href=\"http://www.\\1\" target=\"_blank\">\\1</a>",
          '/(?<!\\\\)\[url(?::\w+)?\](.*?)\[\/url(?::\w+)?\]/si'             => "<a href=\"\\1\" >\\1</a>",
          '/(?<!\\\\)\[url(?::\w+)?=(.*?)?\](.*?)\[\/url(?::\w+)?\]/si'      => "<a href=\"\\1\" >\\2</a>",
          // [quote] 
          '/(?<!\\\\)\[quote(?::\w+)?\](.*?)\[\/quote(?::\w+)?\]/si'         => "<div>Цитата:<div style=\"border: 1px solid #cccccc; background-color: #e8e8e8; padding: 10px\">\\1</div></div>", 
          '/(?<!\\\\)\[quote(?::\w+)?=(?:&quot;|"|\')?(.*?)["\']?(?:&quot;|"|\')?\](.*?)\[\/quote\]/si'   => "<div>\\1:<div style=\"border: 1px solid #cccccc; background-color: #e8e8e8; padding: 10px\">\\2</div></div>", 
          // escaped tags like \[b], \[u], \[url], ... 
          '/\\\\(\[\/?\w+(?::\w+)*\])/'                                      => "\\1", 

          //nl2br fix 
//        '/\n/' => '<br>'

  ); 
  return preg_replace(array_keys($preg), array_values($preg), $message); 
} 
?>